package DesignPatern.A15_组合模式.QSB.A04_抽象模式;

/**
 * @Author: Du
 * @Date: 2021/8/2 10:53
 */
public class A01_Main
{
    public static void main(String[] args)
    {
        Composite root = new Composite();
        Composite branch1 = new Composite();
        Composite branch2 = new Composite();
        Leaf leaf1 = new Leaf(1);
        Leaf leaf2 = new Leaf(2);
        branch1.add(leaf1);
        branch1.add(leaf2);
        
        branch2.add(leaf1);
        branch2.add(leaf2);
        
        root.add(branch1);
        root.add(branch2);
        display(root);
    }
    
    public static void display(Composite composite)
    {
        for (Component child : composite.getChildren())
        {
            if (child instanceof Leaf)
            {
                System.out.println(child.Count());
            } else
            {
                display((Composite) child);
            }
        }
    }
}
